package com.xuelang.pipeline.artifact.app.nexus3v1.config;

import com.xuelang.pipeline.artifact.client.common.constant.ArtifactConstant;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHeaders;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @author xiwen.zxg
 * @since 2024/7/10
 */
@Slf4j
public class Nexus3v1UiFeignConfig implements RequestInterceptor, ApplicationContextAware {
    private ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.context = applicationContext;
    }

    private String getInstanceRepositoryAuthorization() {
        String property = context.getEnvironment().getProperty("pipeline.artifact.authorization.nexus3");
        log.info("pipeline.artifact.authorization.nexus3={}", property);
        return property;
    }

    @Override
    public void apply(RequestTemplate requestTemplate) {
        requestTemplate.header(HttpHeaders.AUTHORIZATION, getInstanceRepositoryAuthorization());
    }

}
